/*
 * redmicro all Copyright (c)
 */

/**
 * Created by seeker910 on 2015/5/17.
 */
Rsd.define('Rsd.Faith.pages.BizZiJinShiYongShenQingListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: ['Rsd.Faith.controls.XiaoQuInput',  'Rsd.controlEx.ComboBoxEnum', 'Rsd.Faith.controls.SuoShuQiInput', 'Rsd.control.TextArea'],
    xtype: 'list-shenQing',
    border: false,
    tabTitle: '资金使用申请列表',
    formTitle: '资金使用申请',
    modelType: 'Rsd.Faith.Models.UsingZiJinShiYongShenQingBiaoModel',
    titleField:'ShenQingDanHao',
    sort:[{name:'ShenQingRiQi',direction:'desc'}],
    searchColumns:[
        {name:'XiaoQuBianHao',text:'小区编号'},
        {name:'SuoShuQi',text:'所属期',xtype:'ctrl-suoshuqi'},
        {name:'ShenQingDanHao',text:'申请单号'},
        {name:'ZhuangTai',text:'状态', "xtype": "combobox-enum", "enum": "Rsd.Faith.Core.ZiJinShenQinZhuangTai"}
    ],
    formFields: [
        {
            "name": "XiaoQuBianHao",
            "label": {
                "text": "小区编号",
                "width": 120
            },
            readOnly:true,
            "xtype": 'ctrl-xiaoqu'
        },
        {
            "name": "LouDongHao",
            "label": {
                "text": "楼栋号",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingDanHao",
            "label": {
                "text": "申请单号",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingDanWei",
            "label": {
                "text": "申请单位",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingDanWeiFaRenDaiBiao",
            "label": {
                "text": "申请单位法人代表",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingShiXiang",
            "label": {
                "text": "申请事项",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingRiQi",
            "label": {
                "text": "申请日期",
                "width": 120
            },
            readOnly:true,
            "xtype": "date",
            textChanged: 'ri_qi_changed',
            "formatString": "yyyy-MM-dd"
        },
        {
            "name": "SuoShuQi",
            "label": {
                "text": "所属期",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShenQingJinE",
            "label": {
                "text": "申请金额",
                "width": 120
            },
            readOnly:true,
            "textChanged":'jin_e_changed',
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "ShenQingJinEDaXie",
            "label": {
                "text": "申请金额大写",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "WeiXiuFanWei",
            "label": {
                "text": "维修范围",
                "width": 120
            },
            readOnly:true,
            height: 60,
            "xtype": "textarea"
        },
        {
            "name": "ShouKuanYinHang",
            "label": {
                "text": "收款银行",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "ShouKuanYinHangZhangHao",
            "label": {
                "text": "收款银行账号",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "BoFuFangShi",
            "label": {
                "text": "拨付方式",
                "width": 120
            },
            readOnly:true,
            "xtype": "combobox-enum",
            "enum":"Rsd.Faith.Core.BoFuFangShi",
        },
        {
            "name": "ZhuangTai",
            "label": {
                "text": "状态",
                "width": 120
            },
            readOnly:true,
            "xtype": "combobox-enum",
            "enum": "Rsd.Faith.Core.ZiJinShenQinZhuangTai",
        },
        {
            "name": "Remark",
            "label": {
                "text": "备注",
                "width": 120
            },
            "xtype": "text"
        }
    ],
    gridColumns: [
        {
            "text": "序号",
            "xtype": "index",
            "width": 40
        },
        {
            "name": "SuoShuQi",
            "dataIndex": "SuoShuQi",
            "sortable": false,
            "text": "所属期",
            align:'center',
            "index": 20,
            "exist": true,
            "xtype": "string",
            "width": 80,
            "nobr": true
        },
        {
            "name": "ShenQingDanHao",
            "text": "申请单号",
            "sortable": true,
            "format":"shen_qing_dan_hao_format",
            "width": 150,
            "nobr": true,
            sortable:true
        },
        {
            "name": "ShenQingRiQi",
            "text": "申请日期",
            "sortable": true,
            "xtype": "date",
            "formatString": "yyyy-MM-dd",
            "width": 100
        },
        {
            "name": "ZhuangTai",
            "text": "状态",
            align:'center',
            "sortable": false,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.ZiJinShenQinZhuangTai",
                "valueMember": "code",
                "items": [
                    {
                        "code": "DJ",
                        "value": 0,
                        "text": "待审核",
                        "color":'blue'
                    },
                    {
                        "code": "TG",
                        "value": 1,
                        "text": "待划拨",
                        "color":'blue'
                    },
                    {
                        "code": "JJ",
                        "value": 2,
                        "text": "不通过",
                        "color":'red'
                    },
                    {
                        "code": "HB",
                        "value": 3,
                        "text": "已划拨",
                        "color":'green'
                    }
                ]
            },
            "width": 70,
            "nobr": true
        },
        {
            "name": "ShenQingDanWei",
            "text": "申请单位",
            "sortable": false,
            "width": 200,
            "nobr": true
        },
        {
            "name": "ShenQingDanWeiFaRenDaiBiao",
            "text": "法人代表",
            "sortable": false,
            "width": 100,
            "nobr": true
        },
        {
            "name": "ShenQingShiXiang",
            "text": "申请事项",
            "sortable": false,
            "width": 250,
            "nobr": true
        },
        {
            "name": "WeiXiuLeiXin",
            "text": "维修类型",
            align:'center',
            "sortable": false,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.WeiXiuLeiXin",
                "valueMember": "code",
                "items": [
                    {
                        "code": "null",
                        "value": 0,
                        "text": "未设置",
                        "color":'blue'
                    },
                    {
                        "code": "YB",
                        "value": 0,
                        "text": "一般维修",
                        "color":'blue'
                    },
                    {
                        "code": "YJ",
                        "value": 1,
                        "text": "应急维修",
                        "color":'red'
                    }
                ]
            },
            "width": 70,
            "nobr": true
       },
        {
            "name": "ShenQingJinE",
            "text": "申请金额",
            "sortable": true,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "XiaoQuBianHao",
            "text": "小区",
            "xtype": 'ctrl-xiaoqu',
            "sortable": true,
            "width": 80,
            "nobr": true
        },
        {
            "name": "LouDongHao",
            "text": "楼栋号",
            "sortable": false,
            align:'center',
            "width": 50,
            "nobr": true
        },
        {
            "name": "WeiXiuFanWei",
            "text": "维修范围",
            "sortable": false,
            "width": 150,
            "nobr": true
        },
        {
            "name": "ShenQingJinEDaXie",
            "text": "申请金额大写",
            "sortable": true,
            "width": 150,
            "nobr": true
        },
        {
            "name": "BoFuFangShi",
            "text": "划拨方式",
            "sortable": true,
            "index": 0,
            "width": 70,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.BoFuFangShi",
                "valueMember": "code",
                "items": [
                    {
                        "code": "WZ",
                        "value": 0,
                        "text": "未知"
                    },
                    {
                        "code": "ZZ",
                        "value": 1,
                        "text": "转账"
                    },
                    {
                        "code": "XJ",
                        "value": 2,
                        "text": "现金"
                    },
                    {
                        "code": "ZP",
                        "value": 3,
                        "text": "支票"
                    }
                ]
            },
            align:'center',
            "nobr": true
        },
        {
            "name": "ShouKuanYinHang",
            "text": "收款银行",
            "sortable": false,
            "width": 150,
            "nobr": true
        },
        {
            "name": "ShouKuanYinHangZhangHao",
            "text": "收款银行账号",
            "sortable": false,
            "width": 150,
            "nobr": true
        },
        {
            "name": "Remark",
            "text": "备注",
            "sortable": false,
            "width": 150,
            "nobr": true
        }
    ],
    templateCols: [
        {
            name: 'space',
            text: '',
            xtype: 'template',
            width: 5,
            hideable: false,
            sortable: false
        }
    ],
    "huaBoFormFields":[
        {
            "name": "ShenQingDanHao",
            "label": {
                "text": "申请单号",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "XiaoQuBianHao",
            "label": {
                "text": "小区编号",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "text"
        },

        {
            "name": "HuaBoBianHao",
            "label": {
                "text": "划拨编号",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "HuaBoRiQi",
            "label": {
                "text": "划拨日期",
                "width": 80
            },
            "index": 0,
            "xtype": "date",
            panelStyle:{marginTop:45,marginLeft:100},
            "formatString": "yyyy-MM-dd"
        },

        {
            "name": "HuaBoFangShi",
            "label": {
                "text": "划拨方式",
                "width": 80
            },
            "index": 0,
            "xtype": "combobox-enum",
            "enum":"Rsd.Faith.Core.BoFuFangShi",
        },
        {
            "name": "HuaBoJinE",
            "label": {
                "text": "划拨金额",
                "width": 80
            },
            "index": 0,
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "FuKuanZhangHu",
            "label": {
                "width": 80,
                "content": "付款账户"
            },
            "dataIndex": "FuKuanZhangHu",
            "index": 27,
            "exist": true,
            "xtype": "combobox-enum",
            "textMember": "text",
            "enum": {
                "name": "Rsd.Faith.Core.FuKuanZhangHu",
                "valueMember": "code",
                "textMember": "text",
                "items": [
                    {
                        "code": "BJ",
                        "value": 0,
                        "text": "资金本金账户"
                    },
                    {
                        "code": "TC",
                        "value": 1,
                        "text": "资金统筹账户"
                    },
                    {
                        "code": "XQTC",
                        "value": 2,
                        "text": "小区统筹账户"
                    },
                    {
                        "code": "LDTC",
                        "value": 3,
                        "text": "小区楼栋统筹账户"
                    },
                    {
                        "code": "DYTC",
                        "value": 4,
                        "text": "小区单元统筹账户"
                    }
                ]
            }
        },
        {
            "name": "FuKuanYinHang",
            "label": {
                "width": 80,
                "content": "付款银行"
            },
            "dataIndex": "FuKuanYinHang",
            "index": 48,
            "exist": true,
            "xtype": "text",
            "length": 250
        },
        {
            "name": "FuKuanYinHangZhangHao",
            "label": {
                "width": 80,
                "content": "付款银行账号"
            },
            "dataIndex": "FuKuanYinHangZhangHao",
            "index": 50,
            "exist": true,
            "xtype": "text",
            "length": 50
        },
        {
            "name": "ShenPiRen",
            "label": {
                "text": "审批人",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        /* {
             "name": "ZhuangTai",
             "label": {
                 "text": "状态",
                 "width": 80
             },
             "index": 0,
             readOnly:true,
             "xtype": "combobox-enum",
             "enum":   "Rsd.Faith.Core.ZiJinHuaBoZhuangTai"
         },*/
        {
            "name": "Remark",
            "label": {
                "text": "备注",
                "width": 80
            },
            "dataindex": "remark",
            "index": 200,
            "xtype": "text"
        }
    ],
    /*
    * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },


    /*
     * */
    shen_qing_dan_hao_format:function shen_qing_dan_hao_format(row){

        var me = this;
        var _fn = function (formData,form) {

            //console.log(formData);
            Rsd.app.requestService('using.ShenQingHuaBo',formData,function (data) {

                if(data.success)
                {
                    Rsd.popup('操作成功');
                }
                else
                {
                    Rsd.alert(data.msg);
                }

            });

            return true;
        };

        var  btnOk = Rsd.button('设置为已划拨',function(){

            var now = new Date();
            var _record = {
                ShenQingDanHao:row['ShenQingDanHao'],
                XiaoQuBianHao:row['XiaoQuBianHao'],
                HuaBoBianHao:row['ShenQingDanHao'],
                HuaBoRiQi:now.format('yyyy-MM-dd'),
                HuaBoFangShi:'ZZ',
                FuKuanZhangHu:'BJ',
                FuKuanYinHang:'',
                FuKuanYinHangZhangHao:'',
                HuaBoJinE:row['ShenQingJinE'],
                ZhuangTai:'DJ'

            };


            var _type = 'Rsd.Faith.Models.UsingZiJinShiYongHuaBoBiaoModel';

            Rsd.app.showModelView(_type,me.huaBoFormFields,_record,'设置申请状态为已划拨',[{text:'确认已划拨',height:40,handler:_fn}],false,me);

        } );

        var  btnCheck = document.createElement('a');
        btnCheck.href='#';
        btnCheck.innerHTML = '审核';

        $(btnCheck).click (function(){
            me.formFields[6].readOnly=true;
            me.formFields[8].readOnly=true;
            me.formFields[10].readOnly=true;
            me.formFields[14].readOnly=true;

            Rsd.app.showModelView(me.modelType,me.formFields,row,'使用申请审批',[{text:'同 意',height:40,handler:'btn_fn_ok'},{text:'拒 绝',height:40,handler:'btn_fn_no'}],false,me);

        } );

        var  btnUpdate = document.createElement('a');
        btnUpdate.href='#';
        btnUpdate.innerHTML = '修改';

        $(btnUpdate).click (function(){
            me.formFields[6].readOnly=false;
            me.formFields[8].readOnly=false;
            me.formFields[10].readOnly=false;
            me.openItem(row,['save','cancel'],false);
        } );

        var  btnDel = document.createElement('a');
        btnDel.href='#';
        btnDel.innerHTML = '删除';

        $(btnDel).click (function(){me.deleteItem(row);} );
        if(row['ZhuangTai'] == 'DJ')
        {
            return [Rsd.newLine(),btnCheck,Rsd.blankspan(),btnUpdate,Rsd.blankspan(),btnDel] ;
        }
        if(row['ZhuangTai'] == 'TG')
        {
            return [Rsd.newLine(),btnOk] ;
        }
        if(row['ZhuangTai']=='JJ')
        {
            return [Rsd.newLine(),btnDel] ;
        }
        if(row['ZhuangTai']=='HB')
        {
            return [Rsd.blankspan()] ;
        }
        return [];
    },
    /*
    * */
    btn_fn_ok :function btn_fn_ok(formData,form)
    {
        var me = this;
        formData.ZhuangTai = 'TG';
        Rsd.app.requestService('biz.save',{modelType:me.modelType ,record:formData},function (data) {
            if(data.success)
            {
                Rsd.popup('操作成功');
            }else
            {
                Rsd.alert(data.msg);
            }
        });
        return true;
    },

    /*
    * */
    btn_fn_no :function btn_fn_no(formData,form)
    {

        var me = this;
        formData.ZhuangTai = 'JJ';
        Rsd.app.requestService('biz.save',{modelType:me.modelType ,record:formData},function (data) {
            if(data.success)
            {
                Rsd.popup('操作成功');
            }else
            {
                Rsd.alert(data.msg);
            }
        });
        return true;
    },
    /*
   * */
    ri_qi_changed:function ri_qi_changed(sender,e)
    {
        sender.parent.parent.parent.setFieldValue('SuoShuQi',sender.getValue().substr(0,4));
    },
    /*
    * */
    jin_e_changed:function (sender,e) {

        sender.parent.parent.parent.setFieldValue('ShenQingJinEDaXie',Rsd.formatCurrencyCN(sender.getValue()));
    }

});
